package com.soonfor.evaluate.activity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;


import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import cn.jesse.nativelogger.NLogger;

import com.estronger.shopmanage.R;
import com.soonfor.evaluate.activity.fragment.Evaluated_IToCustomersFragment;
import com.soonfor.evaluate.activity.fragment.UnEvaluate_IToCustomersFragment;
import com.soonfor.evaluate.adapter.FragmentAdapter;
import com.soonfor.evaluate.base.EvalBaseActivity;
import com.soonfor.evaluate.presenter.Evaluate_IToCustomersPresenter;

/**
 * 作者：DC-DingYG on 2018-10-19 9:20
 * 邮箱：dingyg012655@126.com
 * 我对客户的评价
 */
public class Evaluate_IToCustomersActivity extends EvalBaseActivity<Evaluate_IToCustomersPresenter> {

    private String[] titles = new String[]{"待评价", "已评价"};
    private FragmentAdapter adapter;
    //ViewPage选项卡页面列表
    private List<Fragment> mFragments;
    private List<String> mTitles;

    @BindView(R.id.tvfLeftTilte)
    TextView tvfLeftTilte;
    @BindView(R.id.tvfRightTilte)
    TextView tvfRightTilte;
    @BindView(R.id.imgfNewNotify)
    ImageView imgfNewNotify;
    @BindView(R.id.imgfLeftVernier)
    ImageView imgfLeftVernier;
    @BindView(R.id.imgfRightVernier)
    ImageView imgfRightVernier;
    @BindView(R.id.viewPager)
    ViewPager viewPager;

    UnEvaluate_IToCustomersFragment bgFrament1;
    Evaluated_IToCustomersFragment bgFrament2;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_evaluate_i_to_clients;
    }

    @Override
    protected void initViews() {
        ((TextView)toolbar.findViewById(R.id.tvfTitile)).setText("我对客户的评价");
        mTitles = new ArrayList<>();
        for (int i = 0; i < titles.length; i++) {
            mTitles.add(titles[i]);
        }
        mFragments = new ArrayList<>();
        bgFrament1 = new UnEvaluate_IToCustomersFragment();
        bgFrament2 = new Evaluated_IToCustomersFragment();

        mFragments.add(bgFrament1);
        mFragments.add(bgFrament2);

        adapter = new FragmentAdapter(getSupportFragmentManager(), mFragments, mTitles);
        viewPager.setAdapter(adapter);//给ViewPager设置适配器
        viewPager.setCurrentItem(0);
        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                if(position==0){
                    tvfLeftTilte.setTextColor(Color.parseColor("#ed423a"));
                    tvfRightTilte.setTextColor(Color.parseColor("#333333"));
                    imgfLeftVernier.setVisibility(View.VISIBLE);
                    imgfRightVernier.setVisibility(View.INVISIBLE);
                }else if(position==1){
                    tvfRightTilte.setTextColor(Color.parseColor("#ed423a"));
                    tvfLeftTilte.setTextColor(Color.parseColor("#333333"));
                    imgfRightVernier.setVisibility(View.VISIBLE);
                    imgfLeftVernier.setVisibility(View.INVISIBLE);
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    @Override
    protected void initPresenter() {

    }

    @Override
    protected void updateViews(boolean isRefresh) {

    }

    @OnClick({R.id.rlfNEvaluate_itoclients, R.id.rlfYEvaluate_itoclients})
    void thisOnClick(View v) {
        switch (v.getId()) {
            case R.id.rlfNEvaluate_itoclients:
                changeTab(0);
                break;
            case R.id.rlfYEvaluate_itoclients:
                changeTab(1);
                break;
        }
    }
    private void changeTab(int index){
        try {
            switch (index){
                case 0:
                    if(imgfLeftVernier.getVisibility() != View.VISIBLE){
                        viewPager.setCurrentItem(0);
                    }
                    break;
                case 1:
                    if(imgfRightVernier.getVisibility() != View.VISIBLE){
                        viewPager.setCurrentItem(1);
                    }
                    break;
            }
        }catch (Exception e){
            NLogger.e("切换页签：" + e.getMessage());
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == Activity.RESULT_OK && data != null) {
            switch (requestCode) {
                case UnEvaluate_IToCustomersFragment.REQUEST_CODE_UEITC:
                    adapter.getItem(0).onActivityResult(requestCode, resultCode, data);
                    break;
            }
        }
    }
}
